package com.tanhua.sso.controller;


import com.tanhua.sso.service.HuanxinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user/huanxin")
public class HuanXinController {
    @Autowired
    private HuanxinService huanxinService;

    /**
     * 添加联系人
     * @param userId
     * @param friendId
     * @return
     */
    public ResponseEntity<Void> contactUsers(
            @PathVariable("owner_username")Long userId,
            @PathVariable("friend_username")Long friendId){
        try {
            boolean result = this.huanxinService.contactUsers(userId, friendId);
            if (result){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 发送消息给环信平台
     * @param target
     * @param msg
     * @param type
     * @return
     */
    @PostMapping("message")
    public ResponseEntity<Void> senMsg(@RequestParam("target")String target,
                                       @RequestParam("msg")String msg,
                                       @RequestParam(value = "type",defaultValue = "txt")String type){

        try {
            Boolean result=this.huanxinService.sendMsg(target,msg,type);
            if (result){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }



}
